package com.example.spindrift.Controllers;

import com.example.spindrift.models.SysSong;
import com.example.spindrift.models.UseHistory;
import com.example.spindrift.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/History")
public class HistoryController {
    @Autowired
    HistoryService historyService;


    /**
     * 获取所有历史播放记录
     * @return
     */
    @GetMapping("/getAllHistory")
    public List<UseHistory> getAllHistory(){
        return historyService.getAllHistory();
    }

    /**
     * 根据用户ID获取歌曲信息列表
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/getHistorySongByUser")
    public List<SysSong> getHistorySongByUser(@RequestParam Integer userId){
        return historyService.getHistorySongByUser(userId);
    }

    /**
     * 搜索播放历史
     * @param userId 用户ID
     * @param keyword 歌曲名称关键字
     * @return
     */
    @GetMapping("/searchHistory")
    public List<SysSong> searchHistory(@RequestParam Integer userId,@RequestParam String keyword){
        return historyService.searchHistory(userId,keyword);
    }

    /**
     * 添加一条用户播放记录
     * @param history 历史记录
     * @return
     */
    @PostMapping("/insertHistory")
    public Boolean insertHistory(@RequestBody UseHistory history){
        return historyService.insertHistory(history) > 0;
    }

    /**
     * 删除指定的历史播放记录
     * @param userId 用户ID
     * @return
     */
    @DeleteMapping("/deleteHistoryByUser")
    public Boolean deleteHistoryByUser(@RequestParam Integer userId){
        return historyService.deleteHistoryByUser(userId) > 0;
    }

    /**
     * 根据歌曲ID删除历史播放记录
     * @param song_id 歌曲ID
     * @return
     */
    @DeleteMapping("/deleteHistoryBySong")
    public Boolean deleteHistoryBySong(@RequestParam Integer song_id){
        return historyService.deleteHistoryBySong(song_id) > 0;
    }
}
